package com.smh.a02streamDemo1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Function;
import java.util.stream.Stream;

public class StreamDemo4 {
    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"asd","asd","qwe","zxc","asd","zxc");
        //去重
        //依赖hashcode和equals方法,所以如果是自定义数据类型,要重写方法
        list.stream().distinct().forEach(s-> System.out.println(s));

        ArrayList<String> list2 = new ArrayList<>();
        Collections.addAll(list2,"1","2","3","4","5");
        System.out.println("-------------------");

        //合并流
        Stream.concat(list2.stream(),list.stream().distinct()).forEach(s-> System.out.println(s));

        System.out.println("--------------------------");
        //类型转换
        list2.stream().map(new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return Integer.parseInt(s);
            }
        }).forEach(s-> System.out.println(s));
        System.out.println("-------------------");
        list2.stream().map(s->Integer.parseInt(s)).forEach(s-> System.out.println(s));





    }
}
